Beheerder |
|
$('#filter').keyup(function(event) {
//if esc is pressed or nothing is entered
if ( event.keyCode == 27 || $(this).val() == '' ) {
//if esc is pressed we want to clear the value of search box
$(this).val('');
//we want each row to be visible because if nothing
//is entered then all rows are matched.
$('#productenWrapper fieldset').removeClass('visible').show().addClass('visible');
} else {
//Filter
filter('#wrapper p', $(this).val());
}
});
});
function filter(selector, query) {
query = $.trim(query); //trim white space
query = query.replace(/ /gi, '|'); //add OR for regex
$(selector).each(function() {
if($(this).text().search(new RegExp(query, "i")) < 0) {
$(this).parent().hide();
} else {
$(this).parent().show();
}
});
};
$('#filter').keyup(function(event) { //if esc is pressed or nothing is entered if ( event.keyCode == 27 || $(this).val() == '' ) { //if esc is pressed we want to clear the value of search box $(this).val(''); //we want each row to be visible because if nothing //is entered then all rows are matched. $('#productenWrapper fieldset').removeClass('visible').show().addClass('visible'); } else { //Filter filter('#wrapper p', $(this).val()); } }); }); function filter(selector, query) { query = $.trim(query); //trim white space query = query.replace(/ /gi, '|'); //add OR for regex $(selector).each(function() { if($(this).text().search(new RegExp(query, "i")) < 0) { $(this).parent().hide(); } else { $(this).parent().show(); } }); };
Dit hebben we dan wel met jQuery gemaakt maar je kan vast wel iets bedenken in je eigen project.
De functie zet je buiten je domready. De bovenste code (implementatie) zet je in de domready |